import { createRouter, createWebHashHistory } from 'vue-router'
import HomeView from '../views/home.vue'
import DevView from '../views/dev.vue'

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/home' // 将根路径重定向到开发页面
    },
    {
      path: '/home',
      name: 'home',
      component: HomeView
    },
    {
      path: '/dev',
      name: 'dev',
      component: DevView
    },
    {
      path: '/signed',
      name: 'signed',
      component: () => import('../views/signed.vue')
    },
    {
      path: '/success',
      name: 'success',
      component: () => import('../views/success.vue'),
      beforeEnter: (to, from, next) => {
        if (from.name === 'signed') {
          next()
        } else {
          next('/home')
        }
      }
    },
    {
      path: '/list',
      name: 'list',
      component: () => import('../views/list.vue')
    },
    {
      path: '/user/:id',
      name: 'user-detail',
      component: () => import('../views/user-detail.vue')
    }
  ]
})

export default router
